import { Request, Response } from 'express'
import { danmakuService } from '../services/danmaku'

export const getDanmakus = async (req: Request, res: Response) => {
  try {
    const { roomId } = req.params
    const { startTime = 0, endTime = 0 } = req.query
    const danmakus = await danmakuService.getDanmakus(roomId, Number(startTime), Number(endTime))
    res.json(danmakus)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const getUserDanmakus = async (req: Request, res: Response) => {
  try {
    const { page, limit } = req.query
    const result = await danmakuService.getUserDanmakus(req.user!.id, Number(page), Number(limit))
    res.json(result)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}
